package zjc.bookkeeping.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import zjc.bookkeeping.R;
import zjc.bookkeeping.db.ConsumptionBean;
import zjc.bookkeeping.db.DBManager;
import zjc.bookkeeping.tools.ToolsClass;

public class ConsumptionListAdapter extends BaseAdapter {
    Context context;
    ImageView classIv;
    View classV;
    TextView classTv,time,remarks,money,method;
    List<ConsumptionBean> consumptionBeanList;

    public ConsumptionListAdapter(Context context, List<ConsumptionBean> consumptionBeanList) {
        this.context = context;
        this.consumptionBeanList = consumptionBeanList;
    }

    @Override
    public int getCount() {
        return consumptionBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return consumptionBeanList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ConsumptionBean consumptionBean = consumptionBeanList.get(i);
        view = LayoutInflater.from(context).inflate(R.layout.home_list_item,viewGroup,false);
        classV = view.findViewById(R.id.home_list_iv_class);
        classIv = view.findViewById(R.id.home_list_iv_class);
        classTv = view.findViewById(R.id.home_list_tv_class);
        time = view.findViewById(R.id.home_list_tv_time);
        remarks = view.findViewById(R.id.home_list_tv_remarks);
        money = view.findViewById(R.id.home_list_tv_money);
        method = view.findViewById(R.id.home_list_tv_method);
        String imageName = DBManager.getConsumptionClassImage(consumptionBean.getConsumption_class_name());
        classIv.setImageResource(ToolsClass.getResourceId(imageName));
        classTv.setText(consumptionBean.getConsumption_class_name());
        time.setText(consumptionBean.getConsumption_time());
        remarks.setText(consumptionBean.getConsumption_remarks());
        int j=consumptionBean.getConsumption_kind();
        if(j==0){
            money.setText("-"+String.valueOf(consumptionBean.getConsumption_money()));
        }else if(j==1){
            money.setText("+"+String.valueOf(consumptionBean.getConsumption_money()));
        }else {
            money.setText(String.valueOf(consumptionBean.getConsumption_money()));
        }

        method.setText(consumptionBean.getConsumption_method());
        return view;
    }
}
